package string;

public class ReverseOnlyLetters917 {
    public String reverseOnlyLetters(String s) {
        int begin = 0;
        int end = s.length()-1;
        char[] chars = s.toCharArray();
        while (begin<end){
            while (begin<end&&!Character.isLetter(chars[begin])){
                begin++;
            }
            while (end>begin&&!Character.isLetter(chars[end])){
                end--;
            }

            char temp = chars[begin];
            chars[begin] = chars[end];
            chars[end] = temp;
            begin++;
            end--;

        }
        return String.valueOf(chars);
    }
}
